home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Tapping Into the Keyboard / SysInfoKeyboard / SysInfoKeyboard.cs next >
Encoding:
Text File  |  2001-01-15  |  1.7 KB  |  55 lines

  1. //----------------------------------------------
  2. // SysInfoKeyboard.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class SysInfoKeyboard: SysInfoReflection
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new SysInfoKeyboard());
  13.      }
  14.      public SysInfoKeyboard()
  15.      {
  16.           Text = "System Information: Keyboard";
  17.      }
  18.      protected override void OnKeyDown(KeyEventArgs kea)
  19.      {
  20.           Point pt = AutoScrollPosition;
  21.  
  22.           pt.X = -pt.X;
  23.           pt.Y = -pt.Y;
  24.  
  25.           switch(kea.KeyCode)
  26.           {
  27.           case Keys.Right:
  28.                if ((kea.Modifiers & Keys.Control) == Keys.Control)
  29.                     pt.X += ClientSize.Width;
  30.                else
  31.                     pt.X += Font.Height;
  32.                break;
  33.  
  34.           case Keys.Left:      
  35.                if ((kea.Modifiers & Keys.Control) == Keys.Control)
  36.                     pt.X -= ClientSize.Width;
  37.                else
  38.                     pt.X -= Font.Height;
  39.                break;
  40.                
  41.           case Keys.Down:      pt.Y += Font.Height;        break;
  42.           case Keys.Up:        pt.Y -= Font.Height;        break;
  43.           case Keys.PageDown:  
  44.                pt.Y += Font.Height * (ClientSize.Height / Font.Height);  
  45.                break;
  46.           case Keys.PageUp:    
  47.                pt.Y -= Font.Height * (ClientSize.Height / Font.Height);
  48.                break;
  49.           case Keys.Home:      pt    = Point.Empty;        break;
  50.           case Keys.End:       pt.Y  = 1000000;            break;
  51.           }
  52.           AutoScrollPosition = pt;
  53.      }
  54. }
  55.